
using System;
using System.Windows.Forms;

namespace AntdUI_APPDemo.Controls
{
    public partial class Input : UserControl
    {
        Form form;
        public Input(Form _form)
        {
            form = _form;
            InitializeComponent();
        }

        private void Btn(object sender, EventArgs e)
        {
            if (sender is AntdUI.Button)
            {
            	var btn = (AntdUI.Button)sender;
                btn.Loading = true;
                AntdUI.ITask.Run(() =>
                {
                    System.Threading.Thread.Sleep(2000);
                    btn.Loading = false;
                });
            }
        }

        private void CodeTextChanged(object sender, EventArgs e)
        {
            if (sender is AntdUI.Input)
            {
            	var input = (AntdUI.Input)sender;
                if (!string.IsNullOrWhiteSpace(input.Text))
                {
                    var find = tableLayoutPanel1.Controls.Find("ic" + (input.TabIndex + 1), false);
                    if (find.Length == 1 && find[0] is AntdUI.Input)
                    {
                    	var input_next = (AntdUI.Input)find[0];
                        input_next.Text = "";
                        input_next.Focus();
                    }
                }
                else
                {
                }
            }
        }

        private void CodeKeyPress(object sender, KeyPressEventArgs e)
        {
        	if (e.KeyChar == 8 && sender is AntdUI.Input && ((AntdUI.Input)sender).Text.Length == 0)
            {
            	var input = (AntdUI.Input)sender;
                //Back
                var find = tableLayoutPanel1.Controls.Find("ic" + (input.TabIndex - 1), false);
                if (find.Length == 1 && find[0] is AntdUI.Input)
                {
                	var input_next = (AntdUI.Input)find[0];
                    input_next.Text = "";
                    input_next.Focus();
                }
            }
        }
    }
}